<?php

class Test_View_Smarty {
    
    public function __construct() {
        
        V::addLibrary('third', dirname(V_PATH).'/common-lib/third');
    }
    
    /**
     * 测试编译功能
     * @return boolean
     */
    public function testCompile() {

		$dir = dirname(__FILE__).'/tmp';
		$cacheDir = $dir.'/template_c';
		mkdir($cacheDir, 0777, true);
		file_put_contents($dir.'/test.tpl', 'this is a smarty test: {$word}');

		try{
			$view = View::factory('Smarty', array(
				'template_dir' => $dir,
				'compile_dir' => $cacheDir,
				'template_ext' => 'tpl',
			));

			$view->assign('word', 'hello smarty');
			echo $view->render('test', View::RENDER_NONE);
			unlink($dir.'/test.tpl');
			FS::rmdir($dir);
			return true;
		} catch (Exception $e) {
			echo 'Exception: ', $e->getMessage(), PHP_EOL;
			FS::rmdir($dir);
			return false;
		}
    }
}